Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly start foreground service #7340

Merged
merged 2 commits into from
Nov 20, 2020
Merged

Conversation

tobiasKaminsky
Copy link
Member

@tobiasKaminsky tobiasKaminsky commented Nov 17, 2020

Fix #2010
Fix #6905

This is not done at all, but it prevents from crashing on my test device.
@ezaquarii for some reason the startForeground in PlayerService is not called, when starting a video.
Thus it get killed by Android after a specific time.

Signed-off-by: tobiasKaminsky tobias@kaminsky.me

Testing

Writing tests is very important. Please try to write some tests for your PR.
If you need help, please do not hesitate to ask in this PR for help.

unit tests
instrumented tests
UI tests

  • Tests written, or not not needed

@ezaquarii
Copy link
Collaborator

@tobiasKaminsky this is very strange edge case as video player does not use PlayerService at all - it depends on a media player in VideoView.

It sounds to me like the player service might be receiving unintended events from GUI.

@InfamousUser
Copy link

InfamousUser commented Nov 17, 2020

Tried it, it does not seem to crash, but I think crashing for me is caused by autoupload, which doesn't seem to want to start on this app. I did turn off doze for it. Maybe it needs a bit of time...

@InfamousUser
Copy link

Ok, autoupload started working, it took a while to initialize and well...

The problem is fixed. The problem being the app crash, now the app doesn't crash but instead the whole app or Android system freezes and/or ANR dialogue is shown. This fixed one of the symptoms apparently. Looks like the underlying problem was just exacerbating the crash case, I did not know there was an underlying problem in the first place.

Okay, so the problem for me is app freezing.
Also the ANR dialogue is different now, there's only 2 options whereas there were 3 before.

P.S. Can't even open the app anymore - it stops responding on the initial loading screen.

@tobiasKaminsky
Copy link
Member Author

@tobiasKaminsky this is very strange edge case as video player does not use PlayerService at all - it depends on a media player in VideoView.

It sounds to me like the player service might be receiving unintended events from GUI.

I was confused by that first, too.
When you click on an image it opens PreviewImageFragment
When you click on an audio/video it opens PreviewMediaFragment

PreviewMediaFragment then can do both: play audio or video.
If audio plays and you click "back", then audio continues to play in background (via PlayerService).
I guess that this is then the reason why PlayerService is started.

When you then click on video in PreviewMediaFragment it opens up PreviewVideoActivity to display video in fullscreen…

@tobiasKaminsky
Copy link
Member Author

Reason why PlayerService is started is:

} else if (MimeTypeUtil.isVideo(file)) {
stopAudio();
playVideo();
}

Which is somehow needed:

  • play audio
  • go back -> audio continues in background
  • start a video

@tobiasKaminsky
Copy link
Member Author

@InfamousUser can you test it again, please?

@tobiasKaminsky
Copy link
Member Author

@ezaquarii I found the cause and hopefully a proper fix. Can you review it? :-)

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

@InfamousUser
Copy link

InfamousUser commented Nov 18, 2020

@InfamousUser can you test it again, please?

Ok, autoupload started working, it took a while to initialize and well...

The problem is fixed. The problem being the app crash, now the app doesn't crash but instead the whole app or Android system freezes and/or ANR dialogue is shown. This fixed one of the symptoms apparently. Looks like the underlying problem was just exacerbating the crash case, I did not know there was an underlying problem in the first place.

Okay, so the problem for me is app freezing.
Also the ANR dialogue is different now, there's only 2 options whereas there were 3 before.

P.S. Can't even open the app anymore - it stops responding on the initial loading screen.

Probably same as above, I can't test because of the original problem. The app is frozen solid on startup for 80 seconds (loading screen), then displays frozen main interface.

It also locks the Android interface half the times for up to half a minute, that shouldn't be possible, probably a bug in Android.

@tobiasKaminsky
Copy link
Member Author

Probably same as above, I can't test because of the original problem. The app is frozen solid on startup for 80 seconds (loading screen), then displays frozen main interface.

It also locks the Android interface half the times for up to half a minute, that shouldn't be possible, probably a bug in Android.

Can you create another issue for this?
Please also try to get logcat.

@tobiasKaminsky
Copy link
Member Author

/backport to stable-3.14

@InfamousUser
Copy link

Not sure whether you wanted the log here or in the new issue, but here it is here just in case. Also not sure this is what you mean by logcat, never used it before, this is what I got by finding an app called that.

Nextcloud.txt

@InfamousUser
Copy link

New issue: #7378

@aqaqsubin aqaqsubin mentioned this pull request Nov 20, 2020
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
@tobiasKaminsky
Copy link
Member Author

❗ Rebased ❗

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/7340.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

1 similar comment
@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/7340.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Nov 20, 2020

Codecov Report

Merging #7340 (343561a) into master (843ecb4) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

@@             Coverage Diff              @@
##             master    #7340      +/-   ##
============================================
- Coverage     29.13%   29.10%   -0.04%     
  Complexity        5        5              
============================================
  Files           442      442              
  Lines         34823    34840      +17     
  Branches       4817     4824       +7     
============================================
- Hits          10147    10140       -7     
- Misses        23182    23206      +24     
  Partials       1494     1494              
Impacted Files Coverage Δ Complexity Δ
...n/java/com/nextcloud/client/media/PlayerService.kt 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...cloud/android/ui/preview/PreviewMediaFragment.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...cloud/android/datamodel/UploadsStorageManager.java 66.30% <0.00%> (-1.82%) 0.00% <0.00%> (ø%)
...oud/android/operations/RefreshFolderOperation.java 75.27% <0.00%> (-1.46%) 0.00% <0.00%> (ø%)
...ain/java/com/owncloud/android/db/UploadResult.java 39.74% <0.00%> (-1.29%) 0.00% <0.00%> (ø%)
.../owncloud/android/files/services/FileUploader.java 49.49% <0.00%> (-0.21%) 0.00% <0.00%> (ø%)
...ncloud/android/operations/UploadFileOperation.java 60.26% <0.00%> (ø) 0.00% <0.00%> (ø%)
...oud/android/ui/activity/SyncedFoldersActivity.java 25.67% <0.00%> (+0.98%) 0.00% <0.00%> (ø%)

@nextcloud-android-bot
Copy link
Collaborator

Codacy

Lint

TypemasterPR
Warnings307307
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings27
Correctness Warnings52
Internationalization Warnings9
Multithreaded correctness Warnings9
Performance Warnings72
Security Warnings41
Dodgy code Warnings102
Total312

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings27
Correctness Warnings52
Internationalization Warnings9
Multithreaded correctness Warnings9
Performance Warnings72
Security Warnings41
Dodgy code Warnings102
Total312

@nextcloud-android-bot
Copy link
Collaborator

@AndyScherzinger AndyScherzinger merged commit 9a80066 into master Nov 20, 2020
@delete-merged-branch delete-merged-branch bot deleted the foregroundServiceCrash branch November 20, 2020 20:27
@AndyScherzinger AndyScherzinger added this to the Nextcloud App 3.15.0 milestone Nov 20, 2020
This was referenced Nov 23, 2020
thelittlefireman pushed a commit to thelittlefireman/android that referenced this pull request Mar 19, 2021
Directly start foreground service
Signed-off-by: thelittlefireman <thelittlefireman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash due to PlayerService Context.startForegroundService() did not then call Service.startForeground()
5 participants